﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>WinSetRegion - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The WinSetRegion function changes the shape of the specified window to be the specified rectangle, ellipse, or polygon." />
<meta name="ahk:equiv-v1" content="commands/WinSet.htm#Region" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>WinSetRegion</h1>

<p>Changes the shape of the specified window to be the specified rectangle, ellipse, or polygon.</p>

<pre class="Syntax"><span class="func">WinSetRegion</span> <span class="optional">Options, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h2 id="Parameters">参数</h2>
<dl>
    <dt>Options</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>If blank or omitted, the window is restored to its original/default display area. Otherwise, one or more of the following options can be specified, each separated from the others with space(s):</p>
        <p><strong>Wn</strong>: Width of rectangle or ellipse. 例如: <code>w200</code>.</p>
        <p><strong>Hn</strong>: Height of rectangle or ellipse. 例如: <code>h200</code>.</p>
        <p><strong>X-Y</strong>: Each of these is a pair of X/Y coordinates. 例如, <code>200-0</code> would use 200 for the X coordinate and 0 for the Y.</p>
        <p><strong>E</strong>: Makes the region an ellipse rather than a rectangle. This option is valid only when <strong>W</strong> and <strong>H</strong> are present.</p>
        <p><strong>R[w-h]</strong>: Makes the region a rectangle with rounded corners. 例如, <code>R30-30</code> would use a 30x30 ellipse for each corner. If <strong>w-h</strong> is omitted, 30-30 is used. <strong>R</strong> is valid only when <strong>W</strong> and <strong>H</strong> are present.</p>
        <p><strong>Rectangle or ellipse</strong>: If the <strong>W</strong> and <strong>H</strong> options are present, the new display area will be a rectangle whose upper left corner is specified by the first (and only) pair of <strong>X-Y</strong> coordinates. However, if the <strong>E</strong> option is also present, the new display area will be an ellipse rather than a rectangle. 例如: <code>WinSetRegion "50-0 W200 H250 E", <i>WinTitle</i></code>.</p>
        <p><strong>Polygon</strong>: When the <strong>W</strong> and <strong>H</strong> options are absent, the new display area will be a polygon determined by multiple pairs of <strong>X-Y</strong> coordinates (each pair of coordinates is a point inside the window relative to its upper left corner). 例如, if three pairs of coordinates are specified, the new display area will be a triangle in most cases. The order of the coordinate pairs with respect to each other is sometimes important. In addition, the word <strong>Wind</strong> maybe be present in <em>Options</em> to use the winding method instead of the alternating method to determine the polygon's region.</p>
    </dd>
    <dt>WinTitle</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p>
        <p>识别目标窗口的窗口标题或其他条件. 请参阅 <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
    </dd>
    <dt>WinText</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>如果存在, 此参数必须是目标窗口的单个文本元素的子字符串(和内置的 Window Spy 工具显示的一样). 如果 <a href="DetectHiddenText.htm">DetectHiddenText</a> 为 ON, 那么会检测隐藏文本元素.</p>
    </dd>
    <dt>ExcludeTitle</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>标题中含有此参数值的窗口将被排除.</p>
    </dd>
    <dt>ExcludeText</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>文本中含有此参数值的窗口将被排除.</p>
    </dd>
</dl>

<h2 id="Error_Handling">错误处理</h2>
<p>失败时抛出异常. Failure occurs when: 1) the target window does not exist; 2) one or more <em>Options</em> are invalid; 3) more than 2000 pairs of coordinates were specified; or 4) the specified region is invalid or could not be applied to the target window.</p>

<h2 id="Remarks">备注</h2>
<p>鼠标光标下的窗口的 ID 可以使用 <a href="MouseGetPos.htm">MouseGetPos</a> 来获取.</p>
<p>窗口标题和文本是区分大小写的. 除非 <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> 被打开, 否则不会检测隐藏窗口.</p>

<h2 id="Related">相关</h2>
<p><a href="Win.htm">Win 函数</a>, <a href="Control.htm">Control 函数</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>WinSetRegion "50-0 W200 H250", "ahk_class Notepad"  <em>; Make all parts of Notepad outside this rectangle invisible.</em>
WinSetRegion "50-0 W200 H250 R40-40", "ahk_class Notepad"  <em>; Same as above but with corners rounded to 40x40.</em>
WinSetRegion "50-0 W200 H250 E", "ahk_class Notepad"  <em>; An ellipse instead of a rectangle.</em>
WinSetRegion "50-0 250-0 150-250", "ahk_class Notepad"  <em>; A triangle with apex pointing down.</em>
WinSetRegion , "ahk_class Notepad" <em>; Restore the window to its original/default display area.</em></pre>
</div>

<div class="ex" id="ExAdvanced">
<p><a href="#ExAdvanced">#2</a>: Here is a region with a more complex area. It creates a see-through rectangular hole inside Notepad (or any other window). There are two rectangles specified below: an outer and an inner. Each rectangle consists of 5 pairs of X/Y coordinates because the first pair is repeated at the end to &quot;close off&quot; each rectangle:</p>
<pre>WinSetRegion "0-0 300-0 300-300 0-300 0-0   100-100 200-100 200-200 100-200 100-100", "ahk_class Notepad"</pre>
</div>

</body>
</html>